import 'dart:convert';

import 'package:emby/model/policy.dart';

import 'configuration.dart';

class User {
  User({
    this.name,
    this.serverId,
    this.id,
    this.hasPassword,
    this.hasConfiguredPassword,
    this.hasConfiguredEasyPassword,
    this.lastLoginDate,
    this.lastActivityDate,
    this.configuration,
    this.policy,
  });

  String name;
  String serverId;
  String id;
  bool hasPassword;
  bool hasConfiguredPassword;
  bool hasConfiguredEasyPassword;
  DateTime lastLoginDate;
  DateTime lastActivityDate;
  Configuration configuration;
  Policy policy;

  factory User.fromRawJson(String str) => User.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory User.fromJson(Map<String, dynamic> json) => User(
        name: json["Name"],
        serverId: json["ServerId"],
        id: json["Id"],
        hasPassword: json["HasPassword"],
        hasConfiguredPassword: json["HasConfiguredPassword"],
        hasConfiguredEasyPassword: json["HasConfiguredEasyPassword"],
        lastLoginDate: DateTime.parse(json["LastLoginDate"]),
        lastActivityDate: DateTime.parse(json["LastActivityDate"]),
        configuration: Configuration.fromJson(json["Configuration"]),
        policy: Policy.fromJson(json["Policy"]),
      );

  Map<String, dynamic> toJson() => {
        "Name": name,
        "ServerId": serverId,
        "Id": id,
        "HasPassword": hasPassword,
        "HasConfiguredPassword": hasConfiguredPassword,
        "HasConfiguredEasyPassword": hasConfiguredEasyPassword,
        "LastLoginDate": lastLoginDate.toIso8601String(),
        "LastActivityDate": lastActivityDate.toIso8601String(),
        "Configuration": configuration.toJson(),
        "Policy": policy.toJson(),
      };

  @override
  String toString() {
    return 'User{name: $name, serverId: $serverId, id: $id, hasPassword: $hasPassword, hasConfiguredPassword: $hasConfiguredPassword, hasConfiguredEasyPassword: $hasConfiguredEasyPassword, lastLoginDate: $lastLoginDate, lastActivityDate: $lastActivityDate, configuration: $configuration, policy: $policy}';
  }
}
